package com.java1412.order;

import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RandomRule;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

/**
 * 定义微服务的主启动类
 *
 * @author java1412
 * @since 2023-06-08 10:24:38
 */
@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients // 开启feign的客户端
public class MallOrderApplication {
    public static void main(String[] args) {
        SpringApplication.run(MallOrderApplication.class, args);
    }

    //  向IOC容器注册restTemplate
    @Bean
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }

    // 向IOC容器注册负载均衡策略
    @Bean
    public IRule loadBalancer() {
        return new RandomRule();
    }
}
